package com.gitee.smsdistribution.controller;

import com.gitee.smsdistribution.common_response.ResponseResultBody;
import com.gitee.smsdistribution.common_response.model.CommonResult;
import com.gitee.smsdistribution.model.User;
import com.gitee.smsdistribution.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ResponseResultBody
@AllArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;


    @PostMapping("/login")
    public CommonResult<Void> login(@RequestBody User user, HttpServletResponse response) {
        userService.login(user, response);
        return CommonResult.success();
    }

    @PostMapping("/logout")
    public CommonResult<Void> logout(HttpServletRequest request, HttpServletResponse response) {
        userService.logout(request, response);
        return CommonResult.success();
    }
}
